home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TODOLIST.ARJ / TODOWIN.CPP < prev    next >
Text File  |  1991-11-11  |  4KB  |  149 lines

  1. //---------------------------------------------------------------------
  2. //
  3. //  TODOWIN.CPP - part of TODO example program
  4. //
  5. //      Copyright (c) 1991 by Borland International
  6. //      All Rights Reserved.
  7. //
  8. //---------------------------------------------------------------------
  9.  
  10. #if !defined( __WINDOWS_H )
  11. #include <Windows.h>
  12. #endif  // __WINDOWS_H
  13.  
  14. #if !defined( __ASSERT_H )
  15. #include <assert.h>
  16. #endif  // __ASSERT_H
  17.  
  18. #if !defined( __TODOWIN_H )
  19. #include "TodoWin.h"
  20. #endif  // __TODOWIN_H
  21.  
  22. //---------------------------------------------------------------------
  23. //
  24. //  initialize static data members of class WinBase.
  25. //  NOTE: these are compiler dependent.  If you are not using
  26. //  Borland C++ you will have to replace this code with something
  27. //  that works with your compiler.
  28. //
  29. //---------------------------------------------------------------------
  30.  
  31. extern HANDLE _hInstance, _hPrev;
  32. extern LPSTR _pszCmdline;
  33. extern int _cmdShow;
  34.  
  35. HANDLE WinBase::hInst = _hInstance;
  36.  
  37. HANDLE WinBase::hPrevInst = _hPrev;
  38.  
  39. LPSTR WinBase::cmd = _pszCmdline;
  40.  
  41. int WinBase::show = _cmdShow;
  42.  
  43. //---------------------------------------------------------------------
  44. //
  45. //  members and data for class ModalDialog
  46. //
  47. //---------------------------------------------------------------------
  48.  
  49. ModalDialog *ModalDialog::curDlg = 0;
  50.  
  51. WORD ModalDialog::run()
  52. {
  53.     FARPROC dlgProc =
  54.         MakeProcInstance( (FARPROC)ModalDialog::dlgProc, hInst );
  55.     DialogBox( hInst, getDialogName(), hWnd(), dlgProc );
  56.     FreeProcInstance( dlgProc );
  57.     return result;
  58. }
  59.  
  60. BOOL FAR PASCAL _export ModalDialog::dlgProc( HWND hDlg,
  61.                                               WORD msg,
  62.                                               WORD wParam,
  63.                                               LONG lParam
  64.                                             )
  65. {
  66.     return curDlg->dispatch( hDlg, msg, wParam, lParam );
  67. }
  68.  
  69. BOOL ModalDialog::dispatch( HWND, WORD, WORD, LONG )
  70. {
  71.     return FALSE;
  72. }
  73.  
  74. //---------------------------------------------------------------------
  75. //
  76. //  members and data for class Window
  77. //
  78. //---------------------------------------------------------------------
  79.  
  80. Window *Window::inCreate = 0;
  81. Window *Window::winList = 0;
  82.  
  83. BOOL Window::create()
  84. {
  85.     if( hPrevInst == 0 && registerClass() == FALSE )
  86.         {
  87.         return FALSE;
  88.         }
  89.  
  90.     inCreate = this;            // flag that we're inside CreateWindow()
  91.  
  92.     createWindow();
  93.  
  94.     nextWin = winList;          // insert this object into the Window list
  95.     winList = this;
  96.  
  97.     inCreate = 0;               // now it's OK to use normal dispatching
  98.  
  99.     return TRUE;
  100. }
  101.  
  102. WORD Window::run()
  103. {
  104.     assert( hWnd() != 0 );      // check that we really exist
  105.  
  106.     MSG msg;
  107.     while( GetMessage( &msg, NULL, NULL, NULL ) != 0 )
  108.         {
  109.         TranslateMessage( &msg );
  110.         DispatchMessage( &msg );
  111.         }
  112.     return msg.wParam;
  113. }
  114.  
  115. LONG Window::dispatch( WORD msg, WORD wParam, long lParam )
  116. {
  117.     return DefWindowProc( hWnd(), msg, wParam, lParam );
  118. }
  119.  
  120. LONG FAR PASCAL Window::wndProc( HWND hWnd,
  121.                                  WORD msg,
  122.                                  WORD wParam,
  123.                                  long lParam
  124.                                )
  125. {
  126.  
  127.     Window *cur = Window::winList;
  128.  
  129.     //  look up the handle in our Window list
  130.     while( cur != 0 && cur->hWnd() != hWnd )
  131.         cur = cur->nextWin;
  132.  
  133.     //  normal dispatching
  134.     if( cur != 0 )
  135.         return cur->dispatch( msg, wParam, lParam );
  136.  
  137.     //  if we're inside CreateWindow(), assume that the message is for us
  138.     if( inCreate != 0 )
  139.         {
  140.         inCreate->hWindow = hWnd;
  141.         return inCreate->dispatch( msg, wParam, lParam );
  142.         }
  143.  
  144.     //  otherwise, pass it on to windows
  145.     return DefWindowProc( hWnd, msg, wParam, lParam );
  146. }
  147.  
  148.  
  149.